package com.作业.Day10;

import lombok.Data;


import java.util.Scanner;

public class Homework5 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        User user = new User();
        Computer computer = new Computer();
        while(true){
            service1.initial();
            int i = scanner.nextInt();
            computer.setUserName(service1.Select(i));
            System.out.println("请输入你的姓名");
            user.setUserName(scanner.next());
            System.out.println("要开始了吗(y/n)");
            boolean b1 = service1.startGame(scanner.next());
            if(!b1){
                 continue;
            }
            else
                break;
        }
        System.out.println(user.getUserName() + "VS" + computer.getUserName());
        for (int j = 0; j < 3; j++) {
            if(j==0){
                System.out.println("是否开启(y/n)");
            }
            else
                System.out.println("是否开启下一轮(y/n)");
            boolean b = service1.startGame(scanner.next());
            if(!b) break;
            System.out.println("请出拳：1.剪刀 2，石头 3.布 ");
            int i1 = scanner.nextInt();
            service1.showFirst(i1,computer,user);
        }
        service1.Score(computer,user);

    }
}

@Data
abstract class all {
    String userName;
    int  a;
    /**
     * 出拳
     * @return
     */
     int job() {
    int m=(int) Math.ceil(Math.random()*3);
         switch (m){
             case 1:
                 System.out.print("剪刀");
                 return m;
             case 2:
                 System.out.print("石头");
                 return m;
             case 3:
                 System.out.print("布");
                 return m;
         }
         return m;
    }
}

class User  extends all{

    int job(int a) {
        switch (a){
            case 1:
                System.out.print("剪刀");
                return 1;
            case 2:
                System.out.print("石头");
                return 2;
            case 3:
                System.out.print("布");
                return 3;
        }
        return 0;
    }
}


class Computer extends all{
    public Computer() {
    }
}
class service1 {
    static void initial() {
        System.out.println("************欢迎进入游戏***********");
        System.out.println("**********************************");
        System.out.println("************猜拳，开始**************");
        System.out.println("*********************************");
        System.out.println("出拳规则：1.剪刀 2，石头 3.布 ");
        System.out.print("请选择你的角色（1.刘备 2.曹操 3.孙权）");

    }

    static String Select(int i) {
        switch (i) {
            case 1:
                return "刘备";
            case 2:
                return "曹操";
            case 3:
                return "孙权";
        }
        System.out.println("输入错误");
        return null;
    }
    static boolean   startGame(String is){
        if(is.equals("y")){
            return true;
        }
        else if(is.equals("n"))
            return false;
       System.out.println("输入错误");
           return false;
    }






    static void showFirst(int a,Computer computer,User user){
        System.out.print("你出拳：");
        int user1 = user.job(a);
        System.out.print(user1);

        System.out.println();
        System.out.print(computer.getUserName()+":");
        int b = computer.job();
        System.out.print(b);
        if(user1>b){
            System.out.println(user.getUserName()+"赢了");
            int a1 = user.getA();
            user.setA(a1+1);
        }
        else if(b>user1){
            System.out.println(computer.getUserName()+"赢了");
            int a1 = computer.getA();
            computer.setA(a1+1);
        }
        else
            System.out.println("平手");
    }
   static void Score(Computer computer,User user){
        System.out.println("姓名     得分");
        System.out.println(user.getUserName()+"   "+user.a);
        System.out.println(computer.getUserName()+"   "+computer.a);
    }

}